package org.uni_hi.lsep.gui.test;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class ResultPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	int[] answerResults=null;

	private JLabel totalAnswers=null;

	private JLabel firstTryAnswer;

	private JLabel secondTryAnswer;

	private JLabel moreTryAnswer;

	public ResultPanel(){
		init();
	}
	
	private void init(){
		int i=0;

		GridBagConstraints gridBagConstraints01 = new GridBagConstraints();
		gridBagConstraints01.gridx = 0;
		gridBagConstraints01.ipadx = 20;
		gridBagConstraints01.ipady = 20;
		gridBagConstraints01.gridy = i++;

		GridBagConstraints gridBagConstraints02 = new GridBagConstraints();
		gridBagConstraints02.gridx = 0;
		gridBagConstraints02.ipadx = 20;
		gridBagConstraints02.ipady = 20;
		gridBagConstraints02.gridy = i++;
		GridBagConstraints gridBagConstraints03 = new GridBagConstraints();
		gridBagConstraints03.gridx = 0;
		gridBagConstraints03.ipadx = 20;
		gridBagConstraints03.ipady = 20;
		gridBagConstraints03.gridy = i++;
		GridBagConstraints gridBagConstraints04 = new GridBagConstraints();
		gridBagConstraints04.gridx = 0;
		gridBagConstraints04.ipadx = 20;
		gridBagConstraints04.ipady = 20;
		gridBagConstraints04.gridy = i++;

		i=0;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.fill=GridBagConstraints.WEST;
		//			gridBagConstraints.ipadx = 100;
		//			gridBagConstraints.ipady = 10;
		gridBagConstraints.gridy = i++;
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 1;
		//			gridBagConstraints1.ipadx = 100;
		//			gridBagConstraints1.ipady = 10;
		gridBagConstraints1.gridy = i++;
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.gridx = 1;
		//			gridBagConstraints2.ipadx = 100;
		//			gridBagConstraints2.ipady = 10;
		gridBagConstraints2.gridy = i++;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.gridx = 1;
		//			gridBagConstraints3.ipadx = 145;
		//			gridBagConstraints3.ipady = 10;
		gridBagConstraints3.gridy = i++;
		GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
		gridBagConstraints31.gridx = 1;
		//			gridBagConstraints31.ipadx = 100;
		//			gridBagConstraints31.ipady = 20;
		gridBagConstraints31.gridy = i++;
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.gridx = 1;
		//			gridBagConstraints4.ipadx = 100;
		gridBagConstraints4.gridy = i++;

		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.gray, 1, true), "Auswertung"));
		this.add(getTotalAnswers(),gridBagConstraints01);
		this.add(getFirstTryAnswer(),gridBagConstraints02);
		this.add(getSecondTryAnswer(),gridBagConstraints03);
		this.add(getMoreTryAnswer(),gridBagConstraints04);
		this.add(new JLabel("Fragen und davon"), gridBagConstraints);
		this.add(new JLabel("Richtig beim 1. Versuch"), gridBagConstraints1);
		this.add(new JLabel("Richtig beim 2. Versuch"), gridBagConstraints2);
		this.add(new JLabel("Richtig beim 3. Versuch oder mehr"), gridBagConstraints3);
		this.add(new JLabel("----------------------------"), gridBagConstraints31);
	}
	
	private JLabel getTotalAnswers(){
		if(totalAnswers==null){
			totalAnswers= new JLabel("");
		}
		return totalAnswers;
	}
	
	private JLabel getFirstTryAnswer(){
		if(firstTryAnswer==null){
			firstTryAnswer= new JLabel("");
		}
		return firstTryAnswer;
	}
	
	private JLabel getSecondTryAnswer(){
		if(secondTryAnswer==null){
			secondTryAnswer= new JLabel("");
		}
		return secondTryAnswer;
	}

	private JLabel getMoreTryAnswer(){
		if(moreTryAnswer==null){
			moreTryAnswer= new JLabel("");
		}
		return moreTryAnswer;
	}
	
	public void setAnswerResults(int[] results){
		if(results!=null){
			int max=Math.max(results[0], results[1]);
			max=results[0]+results[1]+results[2];
			totalAnswers.setText(""+max);
			firstTryAnswer.setText(""+results[0]);
			secondTryAnswer.setText(""+results[1]);
			moreTryAnswer.setText(""+results[2]);
		}
	}
}
